<?php 
//模型：用户登录
//model/class.login.php
//By QINIAO

class qiLogin
{
	var $db;
	
	function qiLogin($dbhandle)
	{
		$this->db = $dbhandle;
	}
	
	//用户登录后台验证
	function userLoginAdmin($username,$password)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."users where username='$username'");
	$num = $this->db->num_rows($res);
	if($num < 1)
	{
	$loginMsg = "没有这个用户";
	}
	else
	{
	$row = $this->db->fetch_array($res);
	if($row['password'] != $password)
	{
	$loginMsg = "密码输入错误";
	}
	elseif($row['isadmin'] != 1)
	{
	$loginMsg = "你不是管理员";
	}
	else
	{
	setcookie('username',$username,$cookietime);
	setcookie('password',$password,$cookietime);
	header("Location: index.php");
	}
	}	
	}
	
	//用户前台登录验证,带验证码
	function userLoginWeb($username,$password,$chekcode,$cookietime)
	{
	if(!empty($username)){
	$res = $this->db->query("select * from ".DB_PREFIX."users where username='$username'");
	$num = $this->db->num_rows($res);
	if($num < 1)
	{
	$notice = "<p align=center><font color=red>该用户不存在，请重新登陆！</font></p>";
	}
	else
	{
	$row = $this->db->fetch_array($res);
	if($row['password'] != $password)
	{
	$notice="<p align=center><font color=red>密码输入错误，请重新登陆！</font></p>";
	}
	elseif($chekcode != $_SESSION['code'])
	{
	$notice = "<p align=center><font color=red>验证码输入不正确！</font></p>";
	}
	else
	{
	setcookie('username',$username,$cookietime);
	setcookie('password',$password,$cookietime);
    redirect('index.php', 2, '登陆成功，3秒钟后跳转到首页！');
	}
	}
	}
	}
	
	//判断用户是否登录
	function userIsLogin()
	{
	
	}
	
	}

?>